/*
 * Copyright (c) 2010 Network Security Lab (NSL), Department of Electrical
 *                    Engineering, University of Washington
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: He Wu mdzz@uw.edu
 */

/**
 * @file command.h
 * @brief Packet handler methods.
 *
 * All packets are handled by a single function and then forwarded to different
 * handlers.
 */

#ifndef COMMAND_H
#define COMMAND_H

#include "network.h"

/******************************************************************************/

#define MAX_SEQ 3 //!< maximum number of sequence number records to keep

/**
 * Sequence number record.
 */
typedef struct seq_num_record_st {
  __u8 seq;   //!< sequence number
  __u16 addr; //!< sender of packet
} seq_num_record;

/******************************************************************************/

/**
 * Initializes sequence number list.
 */
void init_seq_list();

/**
 * @brief Filters and forward the received packet to corresponding handlers.
 * @param in_pkt Pointer to received packet.
 */
void pkt_processor(packet *in_pkt);

/**
 * @brief Forwards packets to base node using routing information.
 * @param out_pkt Pointer to packet being sent.
 * @param ACK_en Set to enable ACK.
 * @return 0 if all is good.
 */
int forward_to_base(packet *out_pkt, int ACK_en);

/**
 * @brief Forward packet to node using routing information.
 * @param out_pkt Pointer to packet to be sent.
 * @param ACK_en Set to enable ACK
 * @return 0 if all is good.
 */
int forward_to_node(packet *out_pkt, int ACK_en);

/**
 * Toggles green LED.
 */
void toggle_green();

/**
 * Turn on green LED.
 */
void on_green();

/**
 * Turn off green LED.
 */
void off_green();

/**
 * Toggle red LED.
 */
void toggle_red();

/**
 * Turn on red LED.
 */
void on_red();

/**
 * Turn off red LED.
 */
void off_red();

/**
 * Toggle blue LED.
 */
void toggle_blue();

/**
 * Turn on blue LED.
 */
void on_blue();

/**
 * Turn off blue LED.
 */
void off_blue();

/**
 * @brief Send a list of command to nodes, using routing information.
 * @param cmd_list Pointer to list of commands to be sent.
 * @return 0 if all is good.
 *
 * Each command is 14 bytes long.
 */
int send_cmd(__u8 *cmd_list);

#endif
